package com.house.log;

import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Component
@Aspect   //切面类
@Slf4j
public class LogAspect {


    @Pointcut("execution(public * com.house.service.*.*(..)) || @annotation(com.house.log.HOUSELog)")
    public void aopLog(){}

    @Before("aopLog()")
    public void doBefore(JoinPoint joinPoint){
        Object[] args = joinPoint.getArgs(); //参数
        Signature signature = joinPoint.getSignature();//方法名
        log.info("进入方法：{}，参数：{}", signature, args);
    }

    @AfterReturning(pointcut="aopLog()",returning = "obj")
    public void doAfter(Object obj){
        log.info("返回结果：{}", JSONObject.toJSONString(obj));
    }


}
